IcePong

“Nothing is what it looks like, everything is what it is.”

Proverb

Same old dog with a different collar

Welcome to your first game with real graphics! The job of programming a game with apropriate graphics (not to mention drawing the graphics themselves) is very complicated. That's why I tried to concentrate on the escentials in the previous tutorials, while keeping the blackbox code to a minimum. This time I've programmed a clone of the classic Pong. It's called IcePong because once you start moving in a direction you won't stop until you hit a key to move the other way or bounce against the wall. Besides graphics this game also has some rudimentary artifitial intelligence. Try out icepong.gb before reading on.



What you gotta do

This time I want you to handle programming the machine controlled paddle for the game of IcePong. The source you have to work on is icepongnocomputer.gb. The subroutine you need to fill in is ComputerInput. What is does is set the horizontal speed of the computer controlled paddle. This is done by setting the variable sx2# to either maxspeed# (for moving right) or -maxspeed# (for moving left). The variables you can read for making the decicion of wich way to move are x# and y# (for the ball position) as well as x1# (for the human player's paddle position) and x2# (for the computer paddle's horizontal position). The only other thing is that the screen is set up so that (-1,-1) is the lower left corner and (1,1) is the upper right one.